package com.zw.a.basic.a11.demo04_exercise;

import java.util.ArrayList;
import java.util.Collections;

//案例: 模拟斗地主发牌
public class Demo06_Poker_无序的牌 {
    public static void main(String[] args) {
        //1. 买牌.
        //搞一个牌盒, 用来装扑克牌.
        ArrayList<String> pokers = new ArrayList<>();
        //填充牌
        String[] colors = {"♥", "♠", "♦", "♣"};
        String[] numbers = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"};
        //遍历花色集合
        for (String color : colors) {   //"♥", "♠", "♦", "♣"
            //遍历点数集合
            for (String number : numbers) { //"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"
                pokers.add(color + number);
            }
        }
        //添加大小王
        pokers.add("小王");
        pokers.add("大王");

        //2. 洗牌.
        Collections.shuffle(pokers);

        //3. 发牌.  三个玩家, 一个底牌
        ArrayList<String> lyf = new ArrayList<>();
        ArrayList<String> zly = new ArrayList<>();
        ArrayList<String> hg = new ArrayList<>();
        ArrayList<String> dipai = new ArrayList<>();

        //发牌思路: 1. 最后三张作为底牌.   2. 牌的索引是0到53的, 依次和3取余,  余数为0给第一个人, 余数为1给第二个人, 余数为3给第三个人.
        for (int i = 0; i < pokers.size(); i++) {
            String poker =  pokers.get(i);      //就是每一张牌.
            if (i >= pokers.size() - 3) {       //51, 52, 53
                dipai.add(poker);
            } else if (i % 3 == 0) {
                lyf.add(poker);
            }else if (i % 3 == 1) {
                zly.add(poker);
            }else if (i % 3 == 2) {
                hg.add(poker);
            }
        }

        //4, 看牌.
        lookPoker("刘亦菲", lyf);
        lookPoker("赵丽颖", zly);
        lookPoker("夯哥", hg);
        lookPoker("底牌", dipai);
    }

    //4. 定义方法, 用来看牌
    public static void lookPoker(String name, ArrayList<String> list) {
        System.out.print(name + "的牌是: ");
        for (String poker : list) {
            System.out.print(poker + " ");
        }
        System.out.println();
    }
}
